<?
include('./inc/master.php');

$newest_qa_id = -1;
$qas = '';

// Select the most recent QAs.
if ($result = $db->query("SELECT id, question, answer, aid, source, UNIX_TIMESTAMP(`happened`) FROM qa ORDER BY id DESC LIMIT 6")) {
  
  while ($row = $result->fetch_row()) {
    $newest_qa_id = $newest_qa_id == -1 ? $row[0] : $newest_qa_id;
    
    // Add the QA to the list.
    // TODO: Replace default-profile.jpg with the author's WP avatar.
    $qas .= '<li><p>'. stripslashes($row[1]) .'</p><p>'. stripslashes($row[2]) .'</p><p class="qa-meta">'. stripslashes($row[4]) .'<span>- '. date('M. j, Y, g:iA', $row[5]) .'</span></p></li>';
  }
  
  $result->close();
}

$qas = $qas == '' ? '<li></li>' : $qas;


$smarty->assign('title','Q&A');
$smarty->assign('qa', 1);
$smarty->assign('newest_qa_id', $newest_qa_id);
$smarty->assign('qas', $qas);
$smarty->display('qa.tpl');
?>
